﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using SMS.DAL;

namespace SMS.Web.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CustomerMasterService" in code, svc and config file together.
    public class CustomerMasterService : ICustomerMasterService
    {

        public int SaveCustomer(string userName, Entities.Customer customer, out Entities.SMSException serviceError)
        {
            try
            {
                var retObj = new CustomerDA().SaveObject(userName, customer);
                serviceError = null;
                return retObj.Customer_ID;
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return -1;
            }
        }

        public List<Entities.Customer> SearchCustomer(string userName, string searchText, out Entities.SMSException serviceError)
        {
            try
            {
                var retObj = new CustomerDA().SearchObject(userName, searchText);
                serviceError = null;
                return retObj;
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return null;
            }
        }


        public List<Entities.CustomerTransaction> GetCustomerTransaction(string userName, int customerID, DateTime fromDate, DateTime toDate, out SMS.Entities.SMSException serviceError)
        {
            try
            {
                var retObj = new CustomerDA().GetCustomerTransactionList(userName, customerID, fromDate, toDate);
                serviceError = null;
                return retObj;
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return null;
            }
        }

        public int SaveCustomerTransaction(string userName, Entities.CustomerTransaction transaction, out SMS.Entities.SMSException serviceError)
        {
            try
            {
                var retObj = new CustomerDA().SaveCustomerTransation(userName, transaction);
                serviceError = null;
                return retObj;
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return -1;
            }
        }
    }
}
